package com.bwf.lgqingdan.gui.view;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;

import com.cjj.MaterialRefreshLayout;

/**
 * Created by Administrator on 2016/11/2.
 */

public class CustomRefreshLayout extends MaterialRefreshLayout{
    public CustomRefreshLayout(Context context) {
        super(context);
    }

    public CustomRefreshLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public CustomRefreshLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    private float x,y;
    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        if(!canPull) return false;
        switch (ev.getAction()){
            case MotionEvent.ACTION_DOWN:
                x = ev.getX();
                y = ev.getY();
                break;
            case MotionEvent.ACTION_MOVE:
                if(super.onInterceptTouchEvent(ev) && 2*Math.abs(ev.getX()-x) <Math.abs(ev.getY()-y)){
                    Log.d("CustomRefreshLayout", "不拦截");
                    return super.onInterceptTouchEvent(ev);
                }else{
                    return false;
                }
        }
        return super.onInterceptTouchEvent(ev);
    }

    private boolean canPull = true;

    public void setCanPull(boolean canPull) {
        this.canPull = canPull;
    }
}
